# Selenium 3.x 旧写法
# browser = webdriver.Chrome(executable_path='chromedriver.exe')
# element = browser.find_element_by_id('su')

# Selenium 4.x 新写法
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
import time

# 等待页面加载
time.sleep(3)

# 使用 Service 管理驱动
service = Service(ChromeDriverManager().install())
browser = webdriver.Chrome(service=service)

url = 'https://www.baidu.com'
browser.get(url)


# 使用 By 类进行元素定位
element = browser.find_element(By.ID, 'chat-submit-button')

# 获取标签的属性
print(element.text)
# 获取标签的名字
# print(input.tag_name)

# 获取元素文本
# a = browser.find_element_by_link_text('新闻')
# print(a.text)


# 其他定位方式对照
# find_element_by_name()      -> find_element(By.NAME, "name")
# find_element_by_class_name() -> find_element(By.CLASS_NAME, "class")
# find_element_by_xpath()      -> find_element(By.XPATH, "xpath")
# find_element_by_css_selector() -> find_element(By.CSS_SELECTOR, "css")
